library(snowfall)

sfInit(parallel=TRUE, cpus=8)

sfLibrary(igraph)

mc <- readRDS("maximal-cliques.rds")
scliques <- readRDS("sorted-cliques.rds")
nc <- length(mc)

sfExportAll()

get.reduced.cliques <- function(i)
{
	is.subset <- FALSE

	for (j in c((i+1):nc))
	{
		ci <- scliques[[i]]
		cj <- scliques[[j]]

		if (!(any(ci %in% cj == FALSE)))
		{
			is.subset <- TRUE
			break
		}
	}
	
	if (!is.subset)
	{
		scliques[[i]]
	}
}

rcliques <- sfLapply(1:(nc-1), get.reduced.cliques)
saveRDS(rcliques, "reduced-cliques.rds")

print(length(rcliques))

sfStop()

